unit Unit50; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  DbCtrls, sqldb, db, Unit1;

type

  { TForm50 }

  TForm50 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Datasource1: TDatasource;
    DBComboBox1: TDBComboBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    SQLQuery1: TSQLQuery;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    funcionario : string;
  end; 

var
  Form50: TForm50; 

implementation

{ TForm50 }

procedure TForm50.FormShow(Sender: TObject);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;

  SQLQuery1.SQL.Text := 'select fnc_nombre from funcionario order by fnc_nombre';

  SQLQuery1.Open;

  DBComboBox1.DataField := 'fnc_nombre';
  DBComboBox1.Clear;

  while not SQLQuery1.EOF do
  begin
    DBComboBox1.Items.Add(SQLQuery1.Fields[0].AsString);
    SQLQuery1.Next;
  end;
  
  DBComboBox1.Text := funcionario;
  
  Edit2.Text := FormatFloat('###0.00', StrToFloat(Edit2.Text));
end;

procedure TForm50.FormCreate(Sender: TObject);
begin
  SQLQuery1.DataBase := Form1.PQConnection1;
  SQLQuery1.Transaction := Form1.SQLTransaction1;
end;

procedure TForm50.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TForm50.Button1Click(Sender: TObject);
var
  QueryString : string;
  
begin
  QueryString := 'update retiro_caja set rtc_funcionario = '
    + '(select fnc_cdg from funcionario where fnc_nombre = '''
    + DBComboBox1.Text + '''), rtc_descripcion = ''' + Edit1.Text
    + ''', rtc_monto = ' + Edit2.Text + ' where rtc_cdg = ' + Edit3.Text;
    
  Form1.PQConnection1.ExecuteDirect('begin work;');
  Form1.PQConnection1.ExecuteDirect(QueryString);
  Form1.PQConnection1.ExecuteDirect('commit work;');

  ShowMessage('MODIFICACION EXITOSA');
  
  Close;
end;

procedure TForm50.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;
end;

initialization
  {$I unit50.lrs}

end.

